[Embedded Python] Invoking a method on an object
Posted
by jmucchiello
on Stack Overflow
See other posts from Stack Overflow
or by jmucchiello
Published on 2009-09-01T19:08:33Z
Indexed on
2010/04/17
13:43 UTC
Read the original article
Hit count: 197
Given a PyObject* pointing to a python object, how do I invoke one of the object methods? The documentation never gives an example of this:
PyObject* obj = ....
PyObject* args = Py_BuildValue("(s)", "An arg");
PyObject* method = PyWHATGOESHERE(obj, "foo");
PyObject* ret = PyWHATGOESHERE(obj, method, args);
if (!ret) {
// check error...
}
This would be the equivalent of
>>> ret = obj.foo("An arg")
© Stack Overflow or respective owner